import Vue from "vue";
import App from "./App";
import router from "./router";
import { Toast } from "vant";

import "common/style/index.scss";

Vue.config.productionTip = false;

/* eslint-disable no-new */
new Vue({
  el: "#app",
  router,
  render: h => h(App)
});

// is Weixin?
function isWeixinBrowser() {
  var agent = navigator.userAgent.toLowerCase();
  if (agent.match(/MicroMessenger/i) == "micromessenger") {
    return true;
  } else {
    return false;
  }
}

if (!isWeixinBrowser()) {
  Toast.fail({
    duration: 0, // 持续展示 toast
    forbidClick: true, // 禁用背景点击
    message: "请在微信中打开本页面"
  });
}

// wx disable share
function onBridgeReady() {
  WeixinJSBridge.call("hideOptionMenu");
}
// wx disable share
if (typeof WeixinJSBridge == "undefined") {
  if (document.addEventListener) {
    document.addEventListener("WeixinJSBridgeReady", onBridgeReady, false);
  } else if (document.attachEvent) {
    document.attachEvent("WeixinJSBridgeReady", onBridgeReady);
    document.attachEvent("onWeixinJSBridgeReady", onBridgeReady);
  }
} else {
  onBridgeReady();
}
